require 'rubygems'
require 'active_record'
require 'blog'

class CreateTables < ActiveRecord::Migration
  def self.up
    create_table :sites do |t|
      t.string :type, :null=>false
      t.string :name, :null=>false
      t.string :url, :null=>false
      t.integer :blogid, :null=>false, :default=>0
      t.string :username, :null=>false
      t.string :passwd, :null=>false
    end
    
    create_table :medias do |t|
      t.string :fname, :null=>false
      t.string :ftype, :null=>false
      t.integer :fsize, :null=>false
      t.text :b64data
      t.text :b64thumb
    end
    
    create_table :medialinks do |t|
      t.integer :site_id
      t.integer :media_id
      t.string :murl, :null=>false
    end
    
    create_table :articles do |t|
      t.string :title, :null=>false, :default=>'Untitled'
      t.text :content, :null=>false, :default=>''
      t.string :tags, :null=>false, :default=>''
      t.text :custom, :null=>false, :default=>''
      t.timestamps
    end
    
    create_table :publications do |t|
      t.integer :site_id
      t.integer :article_id
      t.string :pub_id
      t.datetime :published_at
    end
    
    create_table :categories do |t|
      t.integer :owner_id, :null=>false
      t.string :owner_type, :null=>false
      t.string :name, :null=>false
    end
  end
  
  def self.down
    drop_table :sites
    drop_table :media
    drop_table :mpublications
    drop_table :articles
    drop_table :publications
    drop_table :categories
  end
end